#include "ipc_api.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

//functions about linux C lib my be called by utility.so
//so do not call any utility function:  ipclog* 
int ipcGetFileSize(const char *path)
{
	int ret = 0;
	struct stat buf;

	ipcLogCheckNullPointReturnValue(path,-1);
	
	ret = stat(path,&buf);
	if(-1 == ret)
	{
		char buf[BUF_LEN_64];
		snprintf(buf,sizeof(buf),"stat %s failed :",path);
		perror(buf);
	}

	return buf.st_size;
}

void ipcLimitFileSize(const char *path,unsigned int fileSize)
{
	int size = ipcGetFileSize(path);

	if(size >= fileSize)
	{
		char cmd[BUF_LEN_64];
		FILE *fp = NULL;

		snprintf(cmd,sizeof(cmd),"echo > %s",path);
		fp = popen(cmd,"r");
		pclose(fp);
	}

	return;
}
